Ext.define('Lms.rms.ZoneInfoDialog',{
	openWindow : function(config) {
		Ext.apply(this, config);
		this.isEditableMode = false; 
		var title = LocaleUtil.getMessage('rms.label.zone');
		if(typeof(config) != 'undefined'){
			title += LocaleUtil.getMessage('rms.label.detail');
			this.isEditableMode = true;
		}else{
			title += LocaleUtil.getMessage('reg');
		}
		this.dialog = Common.openDialog(title, 500, null, [{
			text : LocaleUtil.getMessage('save'),
			scope : this,
			handler : function(){
				if(!this.form.isValid()) return;
				Common.confirm(LocaleUtil.getMessage('confirm'),LocaleUtil.getMessage('rms.msg.doYouWantToSave'),function(btn){
					if(btn == 'yes'){
						var url;
						if(this.isEditableMode){
							//수정 logic
							url = 'zone/update.do';
						}else{
							//등록 logic
							url = 'zone/create.do';
						}
						this.form.submit({
							url : url,
							params : this.form.getForm().getValues(),
							waitMsg: LocaleUtil.getMessage('rms.msg.waitToSaving'),
							scope : this,
							success : this.onClose,
							failure : Common.failureMessageSubmit
						});
					}
				},this);
			}
		},{
			text : LocaleUtil.getMessage('close'),
			cls : 'blue_button',
			scope : this,
			handler : this.onClose
		}]);
		this.dialog.resizable = true;
//		this.dialog.iconCls = 'detail_search';
		this.dialog.add(this.getForm());
		this.dialog.show();
		if(this.isEditableMode){
			this.getData();
		}
	},
	
	onClose : function(){
		this.dialog.close();
		Ext.getCmp('TimeConfigPanel').zoneGrid.getStore().reload();
	},
	
	getData : function(){
		this.form.load({
			url : 'zone/findInfo.do',
			params : {
				id : this.id
			}
		});
	},
	
	getForm : function(){
		this.form = Ext.widget('form',{
		    frame : false,
		    border : false,
		    region : 'north',
		    bodyPadding: '5 5 0',
	        defaults: {anchor: '100%'},
	        defaultType: 'textfield',
	        fieldDefaults: {
	        	labelAlign : 'right',
                labelWidth: 120,
                msgTarget : 'side'
            },
	        items :[{
	        		xtype : 'hiddenfield',
	        		name : 'id'
	        	},{            	
                    fieldLabel: LocaleUtil.getMessage('rms.label.zoneName'),
                    name: 'name',
                    allowBlank : false,
                    readOnly : false
                },{
                	xtype : 'textarea',
                	fieldLabel: LocaleUtil.getMessage('rms.label.zoneDescription'),
                    name: 'description',
                    grow      : true,
                    readOnly : false
                }
            ]      
		});
		
		return this.form;
	}	
});